package com.example.su_shi_tan_bas_lib.album.impl;

import android.content.Context;
import android.content.DialogInterface;

import androidx.fragment.app.FragmentManager;

import com.example.su_shi_tan_bas_lib.album.bean.FunctionBean;
import com.example.su_shi_tan_bas_lib.album.interfaces.AlbumSource;
import com.example.su_shi_tan_bas_lib.album.interfaces.FailedCallback;
import com.example.su_shi_tan_bas_lib.album.interfaces.SuccessCallback;
import com.example.su_shi_tan_bas_lib.album.ui.AlbumPanel;

public abstract class AnAlbumSource<T extends FunctionBean> implements AlbumSource<T>, DialogInterface.OnDismissListener {

    private AlbumPanel albumUIPresent = null;

    protected T functionBean ;

    public void useCamera() {
        if (functionBean != null) {
            functionBean.setUseCamera(true);
        }

    }

    @Override
    public AnAlbumSource<T> onSuccess(SuccessCallback callback) {
        if (functionBean != null) {
            functionBean.setSuccessCallback(callback);
        }
        return this;
    }

    @Override
    public AnAlbumSource<T> onFailed(FailedCallback callback) {
        if (functionBean != null) {
            functionBean.setFailedCallback(callback);
        }
        return this;
    }

    @Override
    public void onDismiss(DialogInterface dialogInterface) {
        albumUIPresent = null;

    }

    public void execute(FragmentManager ft ) {
        if (albumUIPresent != null) {
            albumUIPresent.dismiss();
        }

        albumUIPresent = AlbumPanel.newInstance();
        albumUIPresent.setFunctionBean(functionBean);
        albumUIPresent.show(ft,albumUIPresent.getClass().getSimpleName());

    }
}
